<?php

require 'global.php';

function _index(){
	extract(user::init());

	$types=$GLOBALS['bar_types'];
	$typeid=kc_get('typeid',2,1);
	
	$db=new db;
	$sql='threadid,typeid,hit,reply,isbest,username,lastusername,lastdate,style,title';
	$url='bar_type_'.$typeid.'_PID.htm';
	$where='typeid='.$typeid;
	$order='lastdate desc,threadid desc';
	$res=$db->select('%s_thread', $sql, $url, $where, $order);
	$title=$types[$typeid].' - '.kc_config('site.bartitle');
	$keywords=$types[$typeid].' '.kc_config('site.barkeywords');
	$description=$types[$typeid].' '.kc_config('site.bardescription');

	$nav.='<a href="/">首页</a> > <a href="./">'.kc_config('site.name').'</a> > <strong>'.kc_config('site.barname').'</strong>';

	$s.='<ul id="typeList">';
	foreach ($types as $key => $type) {
		$s.='<li><a href="bar_type_'.$key.'_1.htm">'.$type.'</a></li>';
	}

	$s.='</ul>';

	$s.='<div class="nav_list_s">';
	$s.='<h2>'.$title.'</h2>';
	if (!empty($res)) {
		$s.='<ul>';
		$s.='<li  class="to_s">';
		$s.='<span>主题</span>';
		$s.='<i>回复/点击</i>';
		$s.='<em>作者</em>';
		$s.='<i>最后回复</i>';
		$s.='<em>回复人</em>';
		foreach ($res as $rs) {
			$s.='<li>';
			$s.='<span>';
			$s.='<a href="bar_type_'.$rs['typeid'].'_1.htm">['.$types[$rs['typeid']].']</a>';
			if ($rs['isbest']) {
				$s.='<a href="bar_best_1.htm">[精华]</a>';
			}
			$s.='<a href="bar_thread_'.$rs['threadid'].'_1.htm"'.(empty($rs['style'])?'':' style="'.$rs['style'].'"').'>'.htmlspecialchars($rs['title']).'</a>';
			if ($ismanage) {
				$s.='<a href="javascript:;" class="manage" onclick="$.kc_ajax({URL:\'bar.php\',CMD:\'edit\',threadid:'.$rs['threadid'].'})"><img src="images/edit.gif"/></a>';
				$s.='<a href="javascript:;" class="manage" onclick="$.kc_ajax({URL:\'bar.php\',CMD:\'delete\',threadid:'.$rs['threadid'].'})"><img src="images/delete.gif"/></a>';
			}
			$s.='</span>';
			$s.='<i>'.$rs['reply'].'/'.$rs['hit'].'</i>';
			$s.='<em>'.htmlspecialchars($rs['username']).'</em>';
			$s.='<i>'.str::formatDate($rs['lastdate'],'m-d',1).'</i>';
			$s.='<em>'.htmlspecialchars($rs['lastusername']).'</em>';
			$s.='</li>';
		}
		$s.='</ul>';
	}
	$s.='</div>';
	$s.='<div class="page_page k_pagelist">'.$db->pagelist.'</div>';

	

	require ROOT.'template/list.html';
}



?>